Skip to content

gh-139497: Clarify dataclass inheritance documentation#153672

Open
harjothkhara wants to merge 1 commit into
python:mainfrom
harjothkhara:codex/gh-139497-dataclass-inheritance-docs
Open

gh-139497: Clarify dataclass inheritance documentation#153672
harjothkhara wants to merge 1 commit into
python:mainfrom
harjothkhara:codex/gh-139497-dataclass-inheritance-docs

Conversation

@harjothkhara

@harjothkhara harjothkhara commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Clarify that the @dataclass decorator is not automatically applied to
subclasses. Undecorated subclasses inherit dataclass fields and generated
methods through the normal MRO, so fields from multiple dataclass bases are not
combined unless the subclass is itself decorated.

Also clarify that kw_only=True applies only to fields defined by the class
being decorated and does not change inherited fields.

The existing reverse-MRO description already covers decorated subclasses, and
the inherited default-ordering error remains documented with the decorator, so
this change avoids duplicating those rules in the inheritance section.

I used Codex to help investigate the behavior and draft the wording. I reviewed and validated the change myself.

Closes #139497.

Validation

  • make -C Doc check
  • make -C Doc html (Sphinx --fail-on-warning)
  • Focused runtime proof on current main covering decorated and undecorated
    multiple inheritance, redecorated subclasses, and inherited fields under
    kw_only=True

@bedevere-app bedevere-app Bot added docs Documentation in the Doc dir skip news labels Jul 13, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs Jul 13, 2026
@harjothkhara harjothkhara force-pushed the codex/gh-139497-dataclass-inheritance-docs branch from 0e1421d to aecd915 Compare July 13, 2026 21:56
@harjothkhara harjothkhara force-pushed the codex/gh-139497-dataclass-inheritance-docs branch from aecd915 to 9a97e98 Compare July 13, 2026 21:59
@read-the-docs-community

read-the-docs-community Bot commented Jul 13, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33573041 | 📁 Comparing 9a97e98 against main (701a7c5)

  🔍 Preview build  

1 file changed
± library/dataclasses.html

@harjothkhara harjothkhara marked this pull request as ready for review July 13, 2026 22:21
@harjothkhara harjothkhara requested a review from ericvsmith as a code owner July 13, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Improve documentation on dataclass inheritance

1 participant